package com.ghck.server.dao;
import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.ghck.server.dao.provider.PatientEventDayProvider;
import com.ghck.server.model.PatientEventDay;
import com.ghck.server.model.query.PatientEventDayQuery;
/**
 * 用户健康数据-每种类型，每天只记录一条  <br>
 * t_patient_event_day <br>
 * v1.0 2016-05-22
 */
 public interface PatientEventDayMapper {
 	
 	/**
 	*根据id删除 用户健康数据-每种类型，每天只记录一条
 	*/
 	@Delete("delete from t_patient_event_day where id=#{id}")
 	public Integer deleteById(Integer id);
 	
 	/**
 	* 批量新增 用户健康数据-每种类型，每天只记录一条
 	*/
 	@InsertProvider(method="batchInsert",type=PatientEventDayProvider.class)
	@Options(useGeneratedKeys=true,keyColumn="id",keyProperty="list[0].id")
 	public Integer batchInsert(List<? extends PatientEventDay> patientEventDays);
 	
 	/**
 	* 新增 用户健康数据-每种类型，每天只记录一条
 	*/
 	@InsertProvider(method="insert",type=PatientEventDayProvider.class)
	@Options(useGeneratedKeys=true)
 	public Integer insert(PatientEventDay domain);
 
 	
 	/**
 	*更新 用户健康数据-每种类型，每天只记录一条
 	*/
 	@UpdateProvider(method="update",type=PatientEventDayProvider.class)
 	public Integer update(PatientEventDay domain);
 	
 	/**
 	*根据ID查询 用户健康数据-每种类型，每天只记录一条
 	*/
	@Select("select * from t_patient_event_day where id=#{id}")
	public PatientEventDay findById(Integer id);
	
	/**
 	*通过query 查询 用户健康数据-每种类型，每天只记录一条
 	*/
 	@SelectProvider(method="findByQuery",type=PatientEventDayProvider.class)
 	public List<PatientEventDay> findByQuery(PatientEventDayQuery query);
 	
 	/**
 	*通过query count总条数
 	*/
 	@SelectProvider(method="countByQuery",type=PatientEventDayProvider.class)
 	public Integer countByQuery(PatientEventDayQuery query);
 	
 	/**
 	* 通过ids查询
 	*/
 	@SelectProvider(method="findByIds",type=PatientEventDayProvider.class)
 	public List<PatientEventDay> findByIds(List<Integer> ids);
 	
 	@Select("select * from t_patient_event_day where user_id=#{userId} and category_id=#{categoryId} and date(action_time) = date(#{actionTime}) order by id desc limit 1")
 	public PatientEventDay findByCategoryIdAndActionTime(@Param("userId") Integer userId,@Param("categoryId") Integer categoryId,@Param("actionTime") Date actionTime);
 	
 	@Select("select * from t_patient_event_day where patient_event_id=#{patientEventId} order by id desc limit 1")
 	public PatientEventDay findByPatientEventId(Integer patientEventId);
 	
 	//获取最近的一条
	@Select("select * from t_patient_event_day where user_id=#{userId} and category_id=#{categoryId} order by action_time desc limit 1")
 	public PatientEventDay findLastByCategoryId(@Param("userId") Integer userId,@Param("categoryId") Integer categoryId);
 	
	
	@Select("select * from t_patient_event_day where user_id=#{userId} and category_id=#{categoryId} order by action_time desc limit #{limit}")
 	public List<PatientEventDay> findLastNByUserId(@Param("userId") Integer userId,@Param("limit") Integer limit,@Param("categoryId") Integer categoryId);
 	
	@Select("select * from t_patient_event_day where category_id=#{categoryId}")
 	public List<PatientEventDay> findAllPatientEventDayByCategoryId(@Param("categoryId") Integer categoryId);
 	
}	